package com.aiju.cash.core.api;

import com.aiju.app.callback.HttpCallback;
import com.aiju.common.http.interceptor.HttpFactory;
import com.aiju.widgit.dialog.DialogHelper;

import java.util.HashMap;
import java.util.Map;

import static com.aiju.app.config.ConfigManager.INIT_SERVER_HOST;

/**
 * 作者：流冥 on 2017/7/3 13:39
 * 说明：
 */

public class StockApi extends BaseApi {
    private String stockList = INIT_SERVER_HOST + "/inventory/list"; //库存清单列表
    private String openSynchronize = INIT_SERVER_HOST + "/shop/openSynchronize"; //开启或者关闭同步功能
    private String updateInventory = INIT_SERVER_HOST + "/inventory/updateInventory"; //商品修改接口
    private String synchronize = INIT_SERVER_HOST + "/goods/synchronize"; //进行同步功能，同步总店下所有分店所有关联的商品的类型和商品；

    private HttpFactory instance;

    public StockApi(DialogHelper dialogHelper) {
        super(dialogHelper);
        instance = HttpFactory.getInstance();
        instance.setDialogHelper(dialogHelper);
    }


    public void setDialogHelper(DialogHelper dialogHelper) {
        instance.setDialogHelper(dialogHelper);
    }


    /**
     * 获取库存列表
     */
    public void getShopList(HttpCallback callback) {
        Map<String, String> map = new HashMap<>();
        map.put("storeId", mUser.getShop().getStoreId());
        map.put("token", mUser.getToken());
        instance.makeProxy().requestPost(stockList, map, callback);
    }

    /**
     * 开启或者关闭同步功能
     */
    public void openSynchronize(String status, HttpCallback callback) {
        Map<String, String> map = new HashMap<>();
        map.put("storeId", mUser.getShop().getStoreId());
        map.put("status", status);
        map.put("token", mUser.getToken());
        instance.makeProxy().requestPost(openSynchronize, map, callback);
    }

    /**
     * 进行同步功能，同步总店下所有分店所有关联的商品的类型和商品
     */
    public void synchronize(HttpCallback callback) {
        Map<String, String> map = new HashMap<>();
        map.put("storeId", mUser.getShop().getStoreId());
        map.put("token", mUser.getToken());
        instance.makeProxy().requestPost(synchronize, map, callback);
    }

    /**
     * 商品库存数量修改接口
     */
    public void updateInventory(int id, int inventory, HttpCallback callback) {
        Map<String, String> map = new HashMap<>();
        map.put("id", String.valueOf(id));
        map.put("inventory", String.valueOf(inventory));
        map.put("token", mUser.getToken());
        instance.makeProxy().requestPost(updateInventory, map, callback);
    }
}
